<%@page import="com.zsgeek.util.PageHelper"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%
	String action = request.getParameter("action");
	PageHelper pageHelper = (PageHelper) request
			.getAttribute("pageHelper");
	if (pageHelper != null) {
		int pageCount = pageHelper.getPageCount();
		String pageIndex = request.getParameter("page");
		int currentIndex = 1;
		if (pageIndex != null) {
			currentIndex = Integer.parseInt(pageIndex);
		}
		if (pageCount > 0) {
%>
<nav>
	<ul class="pagination">
		<li><a href="<%=action%>&page=1" aria-label="Previous"> <span
				aria-hidden="true">首页</span>
		</a></li>
		<li><a
			href="<%=action%>&page=<%=(currentIndex - 1) > 0 ? (currentIndex - 1) : 1%>"
			aria-label="Previous"> <span aria-hidden="true">上一页</span>
		</a></li>
		<%
			Integer start_num = 0;
					Integer end_num = pageCount;
					if (pageCount > 10) {
						start_num = currentIndex - 1;
						end_num = currentIndex + 10;
						if (end_num > pageCount) {
							end_num = pageCount;
						}
						if (pageCount == currentIndex
								|| (pageCount - currentIndex) < 10) {
							start_num = pageCount - 10;
						}

					} else if (pageCount == currentIndex || pageCount <= 10) {
						start_num = 0;
						end_num = pageCount;
					}
					for (int i = start_num; i < end_num; i++) {
		%>
		<li class="<%=(currentIndex == (i + 1)) ? "active" : ""%>"><a
			href="<%=action%>&page=<%=i + 1%>"><%=i + 1%></a></li>
		<%
			}
		%>
		<li><a
			href="<%=action%>&page=<%=(currentIndex + 1) > pageCount ? pageCount
							: (currentIndex + 1)%>"
			aria-label="Next"> <span aria-hidden="true">下一页</span>
		</a></li>
		
		<li><a href="<%=action%>&page=<%=pageCount%>" aria-label="Next">
				<span aria-hidden="true">最后一页</span>
		</a></li>
		<%
			}
		%>
	</ul>
</nav>
<%
	}
%>
